<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <%@ include file="/common/CimsCommon.jsp" %>
   <link rel="stylesheet" href="<%=basePath%>/css/cims/cmmBase.css">
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   
</head>
  
<body style="background-color:#FFFFFF">
<div id="formPageSwap">
  <br/>
<form id="addNewsFormData" name="addNewsFormData" isCheck="true" action="com.jy.modules.common.tcmmquota.controller.TCMmQuotaController">
	<div class="expandSwap">
		<div class="ui-widget-header ui-corner-all">
			<span class="text">合约信息</span>
			<span id="importContract" class="aColor" style="float:right;margin-bottom:10px;text-decoration:underline;cursor:pointer;" onclick=""><b>导入合约</b></span>
		</div>
		<div class="expandContent">
			<!--<input type="button" id="importContract" value="导入合约" style="margin-bottom:10px;" onclick=""/> -->
			<%@include file="contractContent.jsp" %>
		</div>
		<div id="list">
			
		</div>
		<div class="expandContent">
			<div>
				<input type="button" onclick="trial()" value="试算"/>
			</div>
		</div>
		<div class="ui-widget-header ui-corner-all">
			<span class="text">结算信息</span>
		</div>
		<div class="expandContent">
			<table class="formTableSwap" border="0" align="center" cellpadding="0" cellspacing="1" >
				<tr>
				  <th> 结算金额 ：</th>
				  <td > 
					  <input type="text" class="text cims_noborder" id="settleSum" name=""  maxLength="16" value="" readonly/>
				  </td>
				  <th> 需匹配金额：</th>
				  <td > 
				 	 <input type="text" class="text" id="matchSum" name="matchSum"  notNull="false" value="" />
				  </td>
				  <th> 返还金额：</th>
				  <td > 
				 	 <input type="text" class="text cims_noborder" id="" name=""  value="" readonly/>
				  </td>
				</tr>
				<tr>
				  
				  <th> 债权数目：</th>
				  <td > 
				  	<input type="text" class="text cims_noborder" id="creditSum" name=""  maxLength="4" value="" checkType="number" readonly/>
				  </td>
				  <th> 实际匹配金额 ：</th>
				  <td > 
				  	<input type="text" class="text cims_noborder" id="actualMatchSum" name=""  maxLength="4" value=""  readonly/>
				  </td>
				  <th> </th>
				  <td > 
				  </td>
				</tr>
				</table>
		</div>
		<div class="expandToolbar">
			<span class="submitBtn" onclick="toDeal();">购买</span>
			<span class="submitBtn" onclick="parent.tabs.close();">关闭</span>
		</div>
	</div>
<!-- 保存 关闭 按钮 在 查询页面进行控制 -->  
</form>

</div>
<script type="text/javascript" src="<%=basePath%>/js/cims/publicJs/importContract.js"></script>
</body>

 <%@include file="settleList.jsp" %>
<script type="text/javascript">
   $(document).ready(function(){
   		checkedInit();//平台校验不兼容IE
   		Cmm.util.dateInputInit("addNewsFormData");
   		var importBtn=$("#importContract"),
   			table;
		importBtn.on("click",importContract(function(contractCode){
	   			var url=contextRootPath+"/tCMmQuota/queryOneContractAll?contractCode="+contractCode;
			    if(table){
			    	table.url=table.url.split("=")[0]+"=000";
			    	table.query();
			    }
	   			jyAjax(url,null,function(msg){
					//保存成功后，执行查询页面查询方法
		        	var v_status = msg.status;
		        	if(v_status.indexOf('ok') >-1){
		        		var cdto=msg.data.cdto,
		        			cspDto=msg.data.cspDto,
		        			cooperorgDTO=msg.data.cooperorgDTO,
		        			agreementDTO=msg.data.agreementDTO,
		        			url;
	        			table=iframe.iframeObj["table"];
	        			url=table.url;
		        		table.url=url.split("=")[0]+"="+cdto.contractCode+"&dealType="+cimsConstant.DEAL_TYPE_MONTH_BACK;
		        		table.query(); 
		        		console.log(msg.data);
		        		$("input[name=contractCode]").val(cdto.contractCode);
		        		$("input[name=contractName]").val(cdto.contractName);
		        		$("input[name=cooperorgCode]").val(cooperorgDTO.cooperorgCode);
		        		$("input[name=cooperorgName]").val(cooperorgDTO.cooperorgName);
		        		$("input[name=agreementCode]").val(agreementDTO.agreementCode);
		        		$("input[name=agreementName]").val(agreementDTO.agreementName);
		        	}
				});
	   		}));
	   		importBtn.trigger("click");
	});
	
	
	var dealCodes="";
	function trial(){
		var table=iframe.iframeObj["table"],
			ids=table.getSelectedIds(),
			dataMap=table.dataMap,
			settleSum=0,
			matchSum=0,
			actualMatchSum=0;
		dealCodes="";
		$.each(ids,function(i,n){
			var record=dataMap[n];
			settleSum+=typeof record.sumCreditorValue=="number"?record.sumCreditorValue*100:0;
			dealCodes+=record.dealCode+",";
		});
		settleSum=settleSum/100;	
		$("#settleSum").val(settleSum);
		$("#matchSum").val(settleSum);
		$("#actualMatchSum").val(settleSum);
		$("#creditSum").val(ids.length);
	}
	
	function toDeal(){
		if (!CheckUtil.formCheck("addNewsFormData")) {
			return;
		}
		window.location=contextRootPath+"/creditBuy/prepareExecute/toDeal?contractCode="+dtocontractCode.value
		 +"&dealCodes="+dealCodes;
	}
</script>
</html>
